//
//  ViewController.m
//  fmdbDemo
//
//  Created by MyMac on 15/8/5.
//  Copyright (c) 2015年 MyMac. All rights reserved.
//

#import "ViewController.h"
#import "SaveCachesTool.h"
#import "Entity.h"
#import "Person.h"
#import "StudentModel.h"

@interface ViewController ()
//@property(nonatomic,strong)NSMutableDictionary*dict;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
       //[SaveCachesTool createTabelSqliteLanguage:@"create table if not exists dddd (id integer primary key autoincrement,name text,age text,year text);" andpath:@"person.db"];

}
- (IBAction)add:(id)sender {
//    for (int i=0; i<30; i++) {
//        NSMutableDictionary*dict=[NSMutableDictionary dictionary];
//        
//
//        [dict setObject:[NSString stringWithFormat:@"%ld",random()] forKey:@"name"];
//        [dict setObject:[NSString stringWithFormat:@"%ld",random()] forKey:@"age"];
//        [dict setObject:[NSString stringWithFormat:@"%ld",random()] forKey:@"year"];
 // BOOL ret=   [SaveCachesTool insertdataSqliteLanguage:@"insert into aaaa values (:age, :year,:name);" and:dict];
    //    BOOL ret=   [SaveCachesTool insertdataSqliteLanguage:[NSString stringWithFormat:@"insert into dddd (name, age,year) values (%@, %@,%@);",dict[@"name"],dict[@"age"],dict[@"year"]] and:nil];
//      NSLog(@"%ld,%@",(long)ret,dict);
        StudentModel*model=[[StudentModel alloc]init];
        model.name=@"niuhui";
        model.teacher=@"Luojie";
        model.room=[NSString stringWithFormat:@"吖吖%ld",(long)rand()];
        
        [SaveCachesTool saveCoreData:model andClass:NSClassFromString(@"Student")];
        
        
 //   }

    
    
    
    
    
}
- (IBAction)delete:(id)sender {
 // BOOL ret=   [SaveCachesTool deleteDataSqliteLanguage:@"delete from dddd where year='黄金水道建设是国防'"];
//    BOOL ret=   [SaveCachesTool deleteDataSqliteLanguage:@"drop table dddd"];
//
//     NSLog(@"%ld",(long)ret);
  
    
    
    NSDictionary*dict=[NSDictionary dictionaryWithObjectsAndKeys:@"吖吖984943658",@"room",@"Luojie",@"teacher",@"niuhui",@"name",nil];
    
//    StudentModel*model=[[StudentModel alloc]init];
//    model.room=@"吖吖16807";
//    model.name=@"niuhui";
//    model.teacher=@"Luojie";
    
    [SaveCachesTool deletedCoreData:dict andClass:NSClassFromString(@"Student")];
    
    
    
}
- (IBAction)update:(id)sender {
    //文本的话用‘’包装
//    BOOL ret=   [SaveCachesTool updataDataSqliteLanguage:@"update dddd set  year='黄金水道建设是国防' where id>10;"];
//    NSLog(@"%ld",(long)ret);
        NSDictionary*dict1=[NSDictionary dictionaryWithObjectsAndKeys:@"吖吖1622650073",@"room",@"Luojie",@"teacher",@"niuhui",@"name",nil];
    NSDictionary*dict2=[NSDictionary dictionaryWithObjectsAndKeys:@"新数据",@"room",@"Luojie",@"teacher",@"新名字",@"name",nil];
    
    StudentModel*model1=[[StudentModel alloc]init];
    model1.name=@"niuhui";
    model1.teacher=@"Luojie";
    model1.room=@"吖吖282475249";
    StudentModel*model2=[[StudentModel alloc]init];
    model2.name=@"AA啊啊啊";
    model2.teacher=@"AA啊";
    model2.room=@"AA啊";
    
    
    [SaveCachesTool updataCoreDataFromEntity:model1 toEntity:model2 andEntityClass:NSClassFromString(@"Student")];
    
    
    
}
- (IBAction)search:(id)sender {
    
//    NSArray *ret=   [SaveCachesTool searchDataSqliteLanguage:@"select * from dddd where id > 10;"];
//    NSLog(@"%@",ret);
//    
    
  NSArray*ret=  [SaveCachesTool searchCoreDataClass:NSClassFromString(@"Student") andPredicateString:[NSPredicate predicateWithFormat:@"room=%@",@"吖吖16807"]];
    NSLog(@"%@",ret);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
